$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		//save();
		uploadSubmit();
	}
});

function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/usabb/attach/save",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}
		}
	});
}


function uploadSubmit() {
	$.ajax({
		cache: true,
		type: "POST",
		url: "/usabb/attach/upload",
		data: new FormData($('#signupForm')[0]), // 你的formid
		async: false,
		processData: false,//processData 因为data值是FormData对象，不需要对数据处理
		contentType: false,//contentType 因为是由form表单构造的FormData对象，且已声明了属性enctype，所以为false
		error: function (request) {
			parent.layer.alert("网络超时");
		},
		success: function (data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name);
				parent.layer.close(index);
			} else {
				parent.layer.alert(data.msg)
			}
		}
	});

}



function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			}
		},
		messages : {
			name : {
				required : icon + "请输入姓名"
			}
		}
	})
}